<?php

$css = array( 'jquery-ui.css', 'lightbox.css', 'form.css');
$javascript = array('add_common.js');

flep_structure($structure, 'curso');

function include_page($structure){
  $user = &$_SESSION['user'];
  $edit = false;
  $entry = false;
  if(isset($_POST['id'])){
    $structure['where'][0] = sprintf("`%s`.`id`='%s'", $structure['table'], flep_decode($_POST['id']));
    $edit = flep_search_all($structure);
  }
  $entrada_id = $edit ? $structure['data'][0]['entrada_id'] : false;
  $entrada_id = isset($_POST['entrada']) ? flep_decode($_POST['entrada']) : $entrada_id;

  if($entrada_id){
    flep_structure($entrada, 'entrada');
    $entrada['where'][0] = sprintf("`%s`.`id`='%s'", $entrada['table'], $entrada_id);
    $entry = flep_search_all($entrada);
  }
?>
  <b><?php echo (!$edit?'Nuevo ':'')?>Curso</b>
  <br><br><br>
  <form action="store.php?type=curso" method="POST" id="form_curso" autocomplete="off">
    <input type="hidden" value="<?php echo ($edit?flep_encode($structure['data'][0]['id']):'')?>" id="id" name="id">
    <table>
      <tr>
        <td>
          <label>
            <?php echo ($entry?'Entrada # '.flep_get($entrada,'entrada'):'<b style="color: #BF0000;">Seleccione una Entrada</b>'); ?>
            <input type="hidden" value="<?php echo ($entry?flep_encode($entrada['data'][0]['id']):'')?>" required id="entrada_id" name="entrada_id">
          </label>
        </td>
        <td><label style="font-weight: normal;" onclick="flep_curso_search_entrada('<?php echo ($edit?flep_encode($structure['data'][0]['id']):'')?>');">[<?php echo ($entry?'Cambiar':'Seleccionar');?>]</label></td>
      </tr>
      <tr><td>&nbsp;</td></tr>
      <tr>
        <td><label>Docente:</label></td>
        <td><select name="docente_id" id="docente_id" required ><?php
          flep_structure($docentes, 'docente');
          $options = "";
          if (flep_search_all($docentes))
            foreach ($docentes['data'] as $docente) {
            printf('<option data-activo="%s" value="%s" %s>%s</option>', $docente['activo'], flep_encode($docente['id']), ($edit && $structure['data'][0]['docente_id'] === $docente['id'] ? 'selected' : ''), $docente['nombre']);
          }
          ?></select>
        </td>
      <tr>
      <tr>
        <td><label>Nivel:</label></td>
        <td><select name="nivel_id" id="nivel_id" required ><?php
          flep_structure($niveles, 'nivel');
          $options = "";
          if (flep_search_all($niveles))
          foreach ($niveles['data'] as $nivel) {
            printf('<option value="%s" %s>%s %s</option>', flep_encode($nivel['id']), ($edit && $structure['data'][0]['nivel_id'] === $nivel['id'] ? 'selected' : ''), $nivel['nivel'], $nivel['grupo']);
          }
          ?></select>
        </td>
        <tr>
        <tr>
          <td><label>Horario:</label></td>
          <td><select name="horario_id" id="horario_id" required ><?php
            flep_structure($horarios, 'horario');
            $options = "";
            if (flep_search_all($horarios))
              foreach ($horarios['data'] as $horario) {
              printf('<option value="%s" %s>%s</option>', flep_encode($horario['id']), ($edit && $structure['data'][0]['horario_id'] === $horario['id'] ? 'selected' : ''), $horario['horario']);
            }
            ?></select>
          </td>
          <tr>
          <tr>
            <td><label>Idioma:</label></td>
            <td><select name="idioma_id" id="idioma_id" required ><?php
              flep_structure($idiomas, 'idioma');
              $options = "";
              if (flep_search_all($idiomas))
                foreach ($idiomas['data'] as $idioma) {
                printf('<option value="%s" %s>%s</option>', flep_encode($idioma['id']), ($edit && $structure['data'][0]['idioma_id'] === $idioma['id'] ? 'selected' : ''), $idioma['idioma']);
              }
              ?></select>
            </td>
          <tr>
          <tr><td>&nbsp;</td></tr>
          <tr><td>&nbsp;</td></tr>
          <tr>
        <td></td>
        <td><input type="submit" value="Guardar" style="margin-right: 100px;"><input type="reset" value="Limpiar"></td>
      </tr>
    </table>
  </form>
<?php
}

?>
